package com.a.testapi23;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

    static {
        System.loadLibrary("MyJni");
    }

    Button b;
    Button b2;

    class Runn implements Runnable {
        String ss;

        public Runn(String s) {
            ss = s;
        }

        @Override
        public void run() {
            while (running) {
                //System.out.println("aaaa" + ss);
            }
        }
    }
    volatile boolean running = false;

    public native void GetString();
    public native void startjni();
    public native void stopjni();

    final Handler h = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if( msg.what == 1 ) {
                System.out.println("ccur = " + System.currentTimeMillis()/1000);
            } else {
                System.out.println("ccur = " );
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        android

        new Thread(new Runnable() {
            @Override
            public void run() {
                while(true) {
                    final Message m = h.obtainMessage();
                    m.what = 1;
                    h.sendMessageDelayed(m, 1000);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();


//        Thread tp = new Thread(new Runnable() {
//            @Override
//            public void run() {
//                GetString();
//            }
//        });
//        tp.start();
//        tp.setPriority(Thread.MIN_PRIORITY);



//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                while (true) {
//                    Log.e("sleep_java", "cur=" + System.currentTimeMillis()/1000);
//                    try {
//                        Thread.sleep(1000);
//                    } catch (Exception e) {}
//                }
//            }
//        }).start();

//        final Runn runn1 = new Runn("1");
//        final Runn runn2 = new Runn("2");
//        final Runn runn3 = new Runn("3");
//        final Runn runn4 = new Runn("4");




//        b = (Button) findViewById(R.id.btn);
//        b.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startjni();
//
//            }
//        });

//        b2 = (Button) findViewById(R.id.btn2);
//        b2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                stopjni();
////                running = false;
//            }
//        });

    }
}
